package com.weiai.wedding.entity.cases;

import org.springframework.stereotype.Repository;

/**
 * smil
 * @author wangweiheng
 *
 */

@Repository
public class SmilAssember {
	private String smilbody;
	private String headStyle = "<smil> " 
			+ "\n<head> "
			+ "\n	<layout>"
			+ "\n 		<root-layout height=\"100\" width=\"100\"/>"
			+ "\n 		<region id=\"image\" top=\"0%\" left=\"0%\" height=\"67%\" width=\"100%\" fit=\"meet\"/>"
			+ "\n 		<region id=\"text\" top=\"67%\" left=\"0%\" height=\"33%\" width=\"100%\" fit=\"meet\"/>"
			+ "\n 	</layout>"
			+ "\n</head> "
			+ "\n<body> ";
	private String par = "";

	public SmilAssember() {
		smilbody = new String();
		addHead();
	}

	private void addHead() {
		smilbody += headStyle;
	}

	@SuppressWarnings("unused")
	private String addPar(String dur, String img) {
		if (validate(dur) && validate(img)) {
			String par = "\n <par dur=\"" + dur + "\" />";
			par += "\n" + img;
			par += "\n </par>";
			return par;
		} else {
			return null;
		}
	}

	public String addPar() {
		this.par = "\n <par dur=\"60s\">" + par + "\n </par>";
		smilbody = smilbody + par;
		par="";
		return par;
	}

	public boolean addImg(String src) {
		if (validate(src)) {
			par += "\n <img region=\"image\" src=\"" + src + "\"/>";
			return true;
		} else {
			return false;
		}
	}

	public boolean addTxt(String src) {
		if (validate(src)) {
			par += "\n <text region=\"text\" src=\"" + src + "\"/>";
			return true;
		} else {
			return false;
		}
	}

	public String getSmilbody() {
		return smilbody + "\n </body> \n</smil>";
	}

	public void setSmilbody(String smilbody) {
		this.smilbody = smilbody;
	}

	private boolean validate(String data) {
		if (data == null || data.trim().length() == 0) {
			return false;
		} else {
			return true;
		}
	}
	
	public static void main(String[] args) {
		SmilAssember sa = new SmilAssember();
		
		
		sa.addImg("att02.jpg");
		sa.addPar();
		sa.addTxt("att01.txt");
		sa.addPar();
		String smilbody2 = sa.getSmilbody();
		System.out.println(smilbody2);
	}
}
